package com.yannuo.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAdvice {
    @Pointcut("execution(* com.yannuo.service.impl.*.*(..))")
    public void anyMethod(){}

//    @Before("anyMethod()")
//    public void beforeMethod(JoinPoint joinPoint){
//        System.out.println("【前置通知日志】" + joinPoint.toString());
//    }
//
//    @After("anyMethod()")
//    public void afterMethod(JoinPoint joinPoint){
//        System.out.println("后置通知："+joinPoint.toString());
//    }
//
//    @AfterReturning(value = "anyMethod()",returning = "result")
//    public void afterTReturnMethod(JoinPoint joinPoint,Object result){
//        System.out.println("返回通知："+joinPoint.toString());
//        System.out.println("result:"+result);
//    }
//
//    @AfterThrowing(value = "anyMethod()",throwing = "ex")
//    public void afterThrowingMethod(JoinPoint joinPoint,Exception ex){
//        System.out.println("返回通知："+joinPoint.toString());
//        System.out.println("ex:"+ex);
//    }

    @Around("anyMethod()")
    public Object around(ProceedingJoinPoint joinPoint){
        Object obj = null;
        System.out.println("环绕通知："+joinPoint.toString());
        try {
            obj = joinPoint.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
        return obj;
    }
}
